/**
  * <br>JAVACC DEMO 1.0<br>
  * @copy right ius company All rights reserved.<br>
  * <br>
  * @Package com.apache.api.method
*/
package com.apache.method;

import java.lang.reflect.Method;

import com.apache.api.vo.ParamsVo;
import com.apache.exception.BaseException;

/**
  * description: 反射调用的主函数
  * @author Hou DaYu 创建时间：下午02:22:30
  */
public abstract class PlatfromMoethProcessor {

	public abstract Object doService(String key, String methodName, ParamsVo vo) throws BaseException;

	/**
	 * 反射调用类方法32
	 * @param obj    类对象
	 * @param vo     方法数
	 * @return  返回方法执行结果
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	protected Object doInvoke(Class queryclass, String methodName, Object obj, ParamsVo vo) throws Exception {
		Method[] methods = queryclass.getDeclaredMethods();// 获得类的方法集合
		Method method = null;
		if (null != methods) {
			int count = methods.length;
			for (int i = 0; i < count; i++) {
				if (methods[i].getName().equals(methodName)) {// 方法返回方法名
					method = queryclass.getDeclaredMethod(methodName, new Class[] { ParamsVo.class });
					break;
				}
			}
		}
		if (null == method) {//获取父类方法
			method = queryclass.getMethod(methodName, new Class[] { ParamsVo.class });
		}
		return method.invoke(obj, vo);
	}

}
